/**
 * Copyright HCP Technology 
 * www.hcp.vn
 */
package models;

import java.util.Date;
import java.util.List;

import siena.Id;
import siena.Model;
import siena.Query;
import util.Util;

public class CategoryModel extends Model{
	
	@Id
	public Long id;
	
	public String name;
	public String alias;
	public String description;
	public String image;
	public String topAdv;
	public String mainAdv;
	public String bottomAdv;
	public String leftAdv;
	public String rightAdv;
	public Date date;
	
	public CategoryModel(String name){
		this.name = name;
		this.alias = Util.convertUTF8TOASCII(name);
		this.date = new Date();
	}
	
	static Query<CategoryModel> all(){
		return Model.all(CategoryModel.class);
	}
	
	public static List<CategoryModel> listCategory(){
		return all().fetch();
	}

	/**
	 * @param page
	 * @param limit
	 * @return
	 */
	public static List<CategoryModel> findByLimit(int page, int limit) {
		return all().fetch(limit, (page - 1) * Util.PAGE_ITEM);
	}
	
	public static CategoryModel findById(Long id){
		return all().filter("id", id).get();
	}
	
	public static CategoryModel find(String alias){
		return all().filter("alias", alias).get();
	}
	
}
